import request from '/@/utils/request';

enum Api {
  Page = '/api/ckWarning/page',
  Export = '/api/ckWarning/export',
  Detail = '/api/ckWarning/detail',
  TestConnection = '/api/ckWarning/testConnection',
  GetSimpleGoodsList = '/api/ckWarning/getSimpleGoodsList',
}

// 库存预警API
export const useCkWarningApi = () => {
  return {
    // 分页查询库存预警信息
    page: (data: any) =>
      request({
        url: Api.Page,
        method: 'post',
        data,
      }),
    // 导出库存预警信息
    export: (data: any) =>
      request({
        url: Api.Export,
        method: 'post',
        data,
        responseType: 'blob',
      }),
    // 获取库存预警详情
    detail: (id: string) =>
      request({
        url: Api.Detail,
        method: 'get',
        params: { id },
      }),
  };
};

// 兼容性导出（保持原有接口）
export const getCkWarningPage = (params: any) => {
  return request({
    url: Api.Page,
    method: 'post',
    data: params,
  });
};

export const exportCkWarning = (params: any) => {
  return request({
    url: Api.Export,
    method: 'post',
    data: params,
    responseType: 'blob',
  });
};

export const getCkWarningDetail = (id: string) => {
  return request({
    url: Api.Detail,
    method: 'get',
    params: { id },
  });
};

// 测试数据库连接
export const testConnection = () => {
  return request({
    url: Api.TestConnection,
    method: 'get',
  });
};

// 获取简单货品列表
export const getSimpleGoodsList = () => {
  return request({
    url: Api.GetSimpleGoodsList,
    method: 'get',
  });
};

